/* Replication Do-file for Sexism Paper (JHR)
Last updated: July 2022, J. Pan
*/

cd "/Users/jessicapan/Dropbox (JPan)/current_projects/Sexism/FINAL_2015/analysis_0915/collapsed_data/"
global output_JP "/Users/jessicapan/Dropbox (JPan)/current_projects/Sexism/jhr_revision_2021/dofiles/output_JP/"
global data "/Users/jessicapan/Dropbox (JPan)/current_projects/Sexism/analysis_0415/data/"
global collapsed_data "/Users/jessicapan/Dropbox (JPan)/current_projects/Sexism/FINAL_2015/analysis_0915/collapsed_data/"

/*******************************/
/* Table 1: Summary Statistics */
/*******************************/

use CG_tests_0721_temp, clear

putexcel set "${output_JP}table1_sumstats", replace
putexcel A3 = "Mean"
putexcel A4 = "SD"
putexcel A5 = "Max-Min"
putexcel B1 = "1977-2017 (Uncond)"
putexcel C1 = "1977-1997 (Uncond)"
putexcel D1 = "1998-2017 (Uncond)"
putexcel E1 = "1977-2017 (Res)"
putexcel F1 = "1977-1997 (Res)"
putexcel G1 = "1998-2017 (Res)"


putexcel B2 = "Female-Male LFP Gap"
sum lfgap1_7717 [aw = lfgap1_7717_se_wgt] if res_index_mean_sd~=.
putexcel B3 = `r(mean)'
putexcel B4 = `r(sd)'
local diff = `r(max)' - `r(min)'
putexcel B5 = `diff'

sum lfgap1_7797 [aw = lfgap1_7797_se_wgt] if res_index_mean_sd~=.
putexcel C3 = `r(mean)'
putexcel C4 = `r(sd)'
local diff = `r(max)' - `r(min)'
putexcel C5 = `diff'

sum lfgap1_9817 [aw = lfgap1_9817_se_wgt] if res_index_mean_sd~=.
putexcel D3 = `r(mean)'
putexcel D4 = `r(sd)'
local diff = `r(max)' - `r(min)'
putexcel D5 = `diff'

sum lfgap3_7717 [aw = lfgap3_7717_se_wgt] if res_index_mean_sd~=.
putexcel E3 = `r(mean)'
putexcel E4 = `r(sd)'
local diff = `r(max)' - `r(min)'
putexcel E5 = `diff'

sum lfgap3_7797 [aw = lfgap3_7797_se_wgt] if res_index_mean_sd~=.
putexcel F3 = `r(mean)'
putexcel F4 = `r(sd)'
local diff = `r(max)' - `r(min)'
putexcel F5 = `diff'

sum lfgap3_9817 [aw = lfgap3_9817_se_wgt] if res_index_mean_sd~=.
putexcel G3 = `r(mean)'
putexcel G4 = `r(sd)'
local diff = `r(max)' - `r(min)'
putexcel G5 = `diff'

putexcel B6 = "Female-Male Wage Gap, Conditional on Working"

sum wagegap1_7717 [aw = wagegap1_7717_se_wgt] if res_index_mean_sd~=.
putexcel B7 = `r(mean)'
putexcel B8 = `r(sd)'
local diff = `r(max)' - `r(min)'
putexcel B9 = `diff'

sum wagegap1_7797 [aw = wagegap1_7797_se_wgt] if res_index_mean_sd~=.
putexcel C7 = `r(mean)'
putexcel C8 = `r(sd)'
local diff = `r(max)' - `r(min)'
putexcel C9 = `diff'

sum wagegap1_9817 [aw = wagegap1_9817_se_wgt] if res_index_mean_sd~=.
putexcel D7 = `r(mean)'
putexcel D8 = `r(sd)'
local diff = `r(max)' - `r(min)'
putexcel D9 = `diff'

sum wagegap3_7717 [aw = wagegap3_7717_se_wgt] if res_index_mean_sd~=.
putexcel E7 = `r(mean)'
putexcel E8 = `r(sd)'
local diff = `r(max)' - `r(min)'
putexcel E9 = `diff'

sum wagegap3_7797 [aw = wagegap3_7797_se_wgt] if res_index_mean_sd~=.
putexcel F7 = `r(mean)'
putexcel F8 = `r(sd)'
local diff = `r(max)' - `r(min)'
putexcel F9 = `diff'

sum wagegap3_9817 [aw = wagegap3_9817_se_wgt] if res_index_mean_sd~=.
putexcel G7 = `r(mean)'
putexcel G8 = `r(sd)'
local diff = `r(max)' - `r(min)'
putexcel G9 = `diff'

putexcel B10 = "Female Share Nevermarried (Age 20 to 40)"

sum nevermarried_state1 [aw=nevermarried_state1_se_wgt] if res_index_men_mean_sd~=.
putexcel B11 = `r(mean)'
putexcel B12 = `r(sd)'
local diff = `r(max)' - `r(min)'
putexcel B13 = `diff'

sum nevermarried8090_state1 [aw=nevermarried8090_state1_se_wgt] if res_index_men_mean_sd~=.
putexcel C11 = `r(mean)'
putexcel C12 = `r(sd)'
local diff = `r(max)' - `r(min)'
putexcel C13 = `diff'

sum nevermarried0012_state1 [aw=nevermarried0012_state1_se_wgt] if res_index_men_mean_sd~=.
putexcel D11 = `r(mean)'
putexcel D12 = `r(sd)'
local diff = `r(max)' - `r(min)'
putexcel D13 = `diff'

sum rnevermarried_state3 [aw=nevermarried_state3_se_wgt] if res_index_men_mean_sd~=.
putexcel E11 = `r(mean)'
putexcel E12 = `r(sd)'
local diff = `r(max)' - `r(min)'
putexcel E13 = `diff'

sum rnevermarried8090_state3 [aw=nevermarried8090_state3_se_wgt] if res_index_men_mean_sd~=.
putexcel F11 = `r(mean)'
putexcel F12 = `r(sd)'
local diff = `r(max)' - `r(min)'
putexcel F13 = `diff'

sum rnevermarried0012_state3 [aw=nevermarried0012_state3_se_wgt] if res_index_men_mean_sd~=.
putexcel G11 = `r(mean)'
putexcel G12 = `r(sd)'
local diff = `r(max)' - `r(min)'
putexcel G13 = `diff'

putexcel B14 = "Female Age at First Birth (Age 20 to 40)"

sum afc_state1 [aw=afc_state1_se_wgt] if res_index_men_mean_sd~=.
putexcel B15 = `r(mean)'
putexcel B16 = `r(sd)'
local diff = `r(max)' - `r(min)'
putexcel B17 = `diff'

sum afc8090_state1 [aw=afc8090_state1_se_wgt] if res_index_men_mean_sd~=.
putexcel C15 = `r(mean)'
putexcel C16 = `r(sd)'
local diff = `r(max)' - `r(min)'
putexcel C17 = `diff'

sum afc0012_state1 [aw=afc0012_state1_se_wgt] if res_index_men_mean_sd~=.
putexcel D15 = `r(mean)'
putexcel D16 = `r(sd)'
local diff = `r(max)' - `r(min)'
putexcel D17 = `diff'

sum rafc_state3 [aw=afc_state3_se_wgt] if res_index_men_mean_sd~=.
putexcel E15 = `r(mean)'
putexcel E16 = `r(sd)'
local diff = `r(max)' - `r(min)'
putexcel E17 = `diff'

sum rafc8090_state3 [aw=afc8090_state3_se_wgt] if res_index_men_mean_sd~=.
putexcel F15 = `r(mean)'
putexcel F16 = `r(sd)'
local diff = `r(max)' - `r(min)'
putexcel F17 = `diff'

sum rafc0012_state3 [aw=afc0012_state3_se_wgt] if res_index_men_mean_sd~=.
putexcel G15 = `r(mean)'
putexcel G16 = `r(sd)'
local diff = `r(max)' - `r(min)'
putexcel G17 = `diff'

/**************************************************************/
/* Table 2: Mean Overall Sexism in State and Women's Outcomes */
/**************************************************************/

use CG_tests_0721_temp, clear

set more off
reg lfgap1_7717 res_index_mean_sd [pw=lfgap1_7717_se_wgt] 
outreg2 using "${output_JP}table2", bdec(3) se br excel replace
reg wagegap1_7717 res_index_mean_sd [pw=wagegap1_7717_se_wgt] 
outreg2 using "${output_JP}table2", bdec(3) se br excel append
reg nevermarried_state1 res_index_mean_sd [pw=nevermarried_state1_se_wgt]
outreg2 using "${output_JP}table2", bdec(3) se br excel append
reg afc_state1 res_index_mean_sd [pw=afc_state1_se_wgt]
outreg2 using "${output_JP}table2", bdec(3) se br excel append

reg lfgap3_7717 res_index_mean_sd [pw=lfgap3_7717_se_wgt] 
outreg2 using "${output_JP}table2", bdec(3) se br excel append
reg wagegap3_7717 res_index_mean_sd [pw=wagegap3_7717_se_wgt] 
outreg2 using "${output_JP}table2", bdec(3) se br excel append
reg nevermarried_state3 res_index_mean_sd [pw=nevermarried_state3_se_wgt]
outreg2 using "${output_JP}table2", bdec(3) se br excel append
reg afc_state3 res_index_mean_sd [pw=afc_state3_se_wgt]
outreg2 using "${output_JP}table2", bdec(3) se br excel append

/*********************************************************************************************/
/* Table 3: Associations Between Background Sexism, Residential Sexism, and Various Outcomes */
/*********************************************************************************************/

use migrant_data_temp_labor, clear

set more off
xi: reg lf res_index_mean_sdxf res_index_mean_sd res_index_mean_sd_bplxf res_index_mean_sd_bpl i.female*i.year [pw=N_lf], cluster(statefip)
outreg2 using "${output_JP}table3", bdec(3) se br excel replace
xi: reg lf_res res_index_mean_sdxf res_index_mean_sd res_index_mean_sd_bplxf res_index_mean_sd_bpl i.female*i.year [pw=N_lf], cluster(statefip)
outreg2 using "${output_JP}table3", bdec(3) se br excel append

xi: reg lhrwage_emp res_index_mean_sdxf res_index_mean_sd res_index_mean_sd_bplxf res_index_mean_sd_bpl i.female*i.year [pw=N_lf], cluster(statefip)
outreg2 using "${output_JP}table3", bdec(3) se br excel append
xi: reg lhrwage_emp_res res_index_mean_sdxf res_index_mean_sd res_index_mean_sd_bplxf res_index_mean_sd_bpl i.female*i.year [pw=N_lf], cluster(statefip)
outreg2 using "${output_JP}table3", bdec(3) se br excel append

use migrant_data_temp_nonlabor, clear

reg nevermarried res_index_mean_sd res_index_mean_sd_bpl i.year [pw=N_nm], cluster(statefip) 
outreg2 using "${output_JP}table3", bdec(3) se br excel append
reg nevermarried_res res_index_mean_sd res_index_mean_sd_bpl i.year [pw=N_nm], cluster(statefip) 
test res_index_mean_sd=res_index_mean_sd_bpl
local sign_d = sign(_b[res_index_mean_sd]-_b[res_index_mean_sd_bpl]) 
display "Ho: coef >= 0  p-value = " 1-ttail(r(df_r),`sign_d'*sqrt(r(F)))
outreg2 using "${output_JP}table3", bdec(3) se br excel append

reg agefirstchild res_index_mean_sd res_index_mean_sd_bpl i.year [pw=N_nm], cluster(statefip) 
outreg2 using "${output_JP}table3", bdec(3) se br excel append
reg agefirstchild_res  res_index_mean_sd res_index_mean_sd_bpl i.year [pw=N_nm], cluster(statefip) 
test res_index_mean_sd=res_index_mean_sd_bpl
local sign_d = sign(_b[res_index_mean_sd]-_b[res_index_mean_sd_bpl]) 
display "Ho: coef >= 0  p-value = " 1-ttail(r(df_r),`sign_d'*sqrt(r(F)))
outreg2 using "${output_JP}table3", bdec(3) se br excel append

/**************************************************************************************/
/* Table 4: IV Estimates of the Effect of Residential Sexism on Labor Market Outcomes */
/**************************************************************************************/

set more off

use migrant_data_temp_labor, clear

gen outmigration_rate_fxf = outmigration_rate_f*female
gen outmigration_rate_mxf = outmigration_rate_m*female

macro define qualityxf "mathz0 mathz0xf readz0 readz0xf" 
macro define quality_bplxf "mathz0_bpl mathz0_bplxf readz0_bpl readz0_bplxf"
macro define qualityxf_v2 "mathz1 mathz1xf readz1 readz1xf"
macro define controlxf "pfemale_emp_8012_1950 pfemale_emp_8012_1950xf"
macro define eduxf "edum_state edum_statexf"
macro define outmigration "outmigration_rate_f outmigration_rate_m"
macro define outmigrationxf "outmigration_rate_f outmigration_rate_fxf outmigration_rate_m outmigration_rate_mxf"

set logtype text
log using F_stat_table4, replace

set more off
xi: ivreg2 lf_res (res_index_mean_sdxf res_index_mean_sd = geoIVxf geoIV) res_index_mean_sd_bplxf res_index_mean_sd_bpl i.region_bpl*i.female i.female*i.year [pw=N_lf], cluster(statefip) first
outreg2 using "${output_JP}table4", bdec(3) se br excel replace
xi: ivreg2 lf_res (res_index_mean_sdxf res_index_mean_sd = geoIVxf geoIV) res_index_mean_sd_bplxf res_index_mean_sd_bpl i.region_bpl*i.female i.female*i.year $outmigrationxf [pw=N_lf], cluster(statefip) first
outreg2 using "${output_JP}table4", bdec(3) se br excel append
xi: ivreg2 lf_res (res_index_mean_sdxf res_index_mean_sd = geoIVxf geoIV) res_index_mean_sd_bplxf res_index_mean_sd_bpl i.region_bpl*i.female i.female*i.year $outmigrationxf $qualityxf $quality_bplxf [pw=N_lf], cluster(statefip) first
outreg2 using "${output_JP}table4", bdec(3) se br excel append

xi: ivreg2 lhrwage_emp_res (res_index_mean_sdxf res_index_mean_sd = geoIVxf geoIV) res_index_mean_sd_bplxf res_index_mean_sd_bpl i.region_bpl*i.female i.female*i.year [pw=N_wage], cluster(statefip) first
outreg2 using "${output_JP}table4", bdec(3) se br excel append
xi: ivreg2 lhrwage_emp_res (res_index_mean_sdxf res_index_mean_sd = geoIVxf geoIV) res_index_mean_sd_bplxf res_index_mean_sd_bpl i.region_bpl*i.female i.female*i.year $outmigrationxf [pw=N_wage], cluster(statefip) first
outreg2 using "${output_JP}table4", bdec(3) se br excel append
xi: ivreg2 lhrwage_emp_res (res_index_mean_sdxf res_index_mean_sd = geoIVxf geoIV) res_index_mean_sd_bplxf res_index_mean_sd_bpl i.region_bpl*i.female i.female*i.year $outmigrationxf $qualityxf $quality_bplxf [pw=N_wage], cluster(statefip) first
outreg2 using "${output_JP}table4", bdec(3) se br excel append

xi: ivreg2 lf_res (res_index_mean_sdxf res_index_mean_sd = mobIV40_smxf mobIV40_sm) res_index_mean_sd_bplxf res_index_mean_sd_bpl i.region_bpl*i.female i.female*i.year [pw=N_lf], cluster(statefip) first
outreg2 using "${output_JP}table4", bdec(3) se br excel append
xi: ivreg2 lf_res (res_index_mean_sdxf res_index_mean_sd = mobIV40_smxf mobIV40_sm) res_index_mean_sd_bplxf res_index_mean_sd_bpl i.region_bpl*i.female i.female*i.year $outmigrationxf [pw=N_lf], cluster(statefip) first
outreg2 using "${output_JP}table4", bdec(3) se br excel append
xi: ivreg2 lf_res (res_index_mean_sdxf res_index_mean_sd = mobIV40_smxf mobIV40_sm) res_index_mean_sd_bplxf res_index_mean_sd_bpl i.region_bpl*i.female i.female*i.year $outmigrationxf $qualityxf $quality_bplxf [pw=N_lf], cluster(statefip) first
outreg2 using "${output_JP}table4", bdec(3) se br excel append

xi: ivreg2 lhrwage_emp_res (res_index_mean_sdxf res_index_mean_sd = mobIV40_smxf mobIV40_sm) res_index_mean_sd_bplxf res_index_mean_sd_bpl i.region_bpl*i.female i.female*i.year [pw=N_wage], cluster(statefip) first
outreg2 using "${output_JP}table4", bdec(3) se br excel append
xi: ivreg2 lhrwage_emp_res (res_index_mean_sdxf res_index_mean_sd = mobIV40_smxf mobIV40_sm) res_index_mean_sd_bplxf res_index_mean_sd_bpl i.region_bpl*i.female i.female*i.year $outmigrationxf [pw=N_wage], cluster(statefip) first
outreg2 using "${output_JP}table4", bdec(3) se br excel append
xi: ivreg2 lhrwage_emp_res (res_index_mean_sdxf res_index_mean_sd = mobIV40_smxf mobIV40_sm) res_index_mean_sd_bplxf res_index_mean_sd_bpl i.region_bpl*i.female i.female*i.year $outmigrationxf $qualityxf $quality_bplxf [pw=N_wage], cluster(statefip) first
outreg2 using "${output_JP}table4", bdec(3) se br excel append

log close

/******************************************************************************************/
/* Table 5: IV Estimates of the Effect of Residential Sexism on Non-Labor Market Outcomes */
/******************************************************************************************/

log using F_stat_table5, replace

use migrant_data_temp_nonlabor, clear

macro define control "pfemale_emp_8012_1950"
macro define control_bpl "pfemale_emp_8012_1950_bpl"
macro define quality "mathz0 readz0" 
macro define quality_bpl "mathz0_bpl readz0_bpl" 

set more off
xi: ivreg2 nevermarried_res (res_index_mean_sd = geoIV) res_index_mean_sd_bpl i.year i.region_bpl [pw=N_nm], cluster(statefip) first
outreg2 using "${output_JP}table5", bdec(3) se br excel replace
xi: ivreg2 nevermarried_res (res_index_mean_sd = geoIV) res_index_mean_sd_bpl i.year i.region_bpl $outmigration [pw=N_nm], cluster(statefip) first
outreg2 using "${output_JP}table5", bdec(3) se br excel append
xi: ivreg2 nevermarried_res (res_index_mean_sd = geoIV) res_index_mean_sd_bpl i.year i.region_bpl $outmigration $quality $quality_bpl [pw=N_nm], cluster(statefip) first
outreg2 using "${output_JP}table5", bdec(3) se br excel append

xi: ivreg2 agefirstchild_res (res_index_mean_sd = geoIV) res_index_mean_sd_bpl i.year i.region_bpl [pw=N_afc], cluster(statefip) first
outreg2 using "${output_JP}table5", bdec(3) se br excel append
xi: ivreg2 agefirstchild_res (res_index_mean_sd = geoIV) res_index_mean_sd_bpl i.year i.region_bpl $outmigration [pw=N_afc], cluster(statefip) first
outreg2 using "${output_JP}table5", bdec(3) se br excel append
xi: ivreg2 agefirstchild_res (res_index_mean_sd = geoIV) res_index_mean_sd_bpl i.year i.region_bpl $outmigration $quality $quality_bpl [pw=N_afc], cluster(statefip) first
outreg2 using "${output_JP}table5", bdec(3) se br excel append

xi: ivreg2 nevermarried_res (res_index_mean_sd = mobIV40_sm) res_index_mean_sd_bpl i.year i.region_bpl [pw=N_nm], cluster(statefip) first
outreg2 using "${output_JP}table5", bdec(3) se br excel append
xi: ivreg2 nevermarried_res (res_index_mean_sd = mobIV40_sm) res_index_mean_sd_bpl i.year i.region_bpl $outmigration [pw=N_nm], cluster(statefip) first
outreg2 using "${output_JP}table5", bdec(3) se br excel append
xi: ivreg2 nevermarried_res (res_index_mean_sd = mobIV40_sm) res_index_mean_sd_bpl i.year i.region_bpl $outmigration $quality $quality_bpl [pw=N_nm], cluster(statefip) first
outreg2 using "${output_JP}table5", bdec(3) se br excel append

xi: ivreg2 agefirstchild_res (res_index_mean_sd = mobIV40_sm) res_index_mean_sd_bpl i.year i.region_bpl [pw=N_afc], cluster(statefip) first
outreg2 using "${output_JP}table5", bdec(3) se br excel append
xi: ivreg2 agefirstchild_res (res_index_mean_sd = mobIV40_sm) res_index_mean_sd_bpl i.year i.region_bpl $outmigration [pw=N_afc], cluster(statefip) first
outreg2 using "${output_JP}table5", bdec(3) se br excel append
xi: ivreg2 agefirstchild_res (res_index_mean_sd = mobIV40_sm) res_index_mean_sd_bpl i.year i.region_bpl $outmigration $quality $quality_bpl [pw=N_afc], cluster(statefip) first
outreg2 using "${output_JP}table5", bdec(3) se br excel append

log close

/*******************************************************************/
/* Table 6: Mean Male vs. Mean Female Sexism and Women's Outcomes  */
/*******************************************************************/

use CG_tests_0721_temp, clear

set more off
reg lfgap3_7717 res_index_men_mean_sd res_index_female_mean_sd [pw=lfgap3_7717_se_wgt]
outreg2 using "${output_JP}table6", bdec(3) se br excel replace
reg wagegap3_7717 res_index_men_mean_sd res_index_female_mean_sd [pw=wagegap3_7717_se_wgt]
outreg2 using "${output_JP}table6", bdec(3) se br excel append
reg wagegap3_I1a_7717 res_index_men_mean_sd res_index_female_mean_sd [pw=wagegap3_I1a_7717_se_wgt]
outreg2 using "${output_JP}table6", bdec(3) se br excel append
reg nevermarried_state3 res_index_men_mean_sd res_index_female_mean_sd [pw=nevermarried_state3_se_wgt]
outreg2 using "${output_JP}table6", bdec(3) se br excel append
reg afc_state3 res_index_men_mean_sd res_index_female_mean_sd [pw=afc_state3_se_wgt]
outreg2 using "${output_JP}table6", bdec(3) se br excel append

/*********************************************************************/
/* Table 7: Quantiles of Overall Sexist Beliefs and Women's Outcomes */
/*********************************************************************/

use CG_tests_0721_temp, clear

*using percentiles of overall sexism*

reg lfgap3_7717 res_index_p10_sd res_index_p50_sd res_index_p90_sd [pw=lfgap3_7717_se_wgt]
outreg2 using "${output_JP}table7", bdec(3) se br excel replace

test res_index_p10_sd = res_index_p50_sd
local sign_d = sign(_b[res_index_p50_sd]-_b[res_index_p10_sd]) 
display "Ho: coef >= 0  p-value = " 1-ttail(r(df_r),`sign_d'*sqrt(r(F)))
test res_index_p90_sd = res_index_p50_sd
local sign_d = sign(_b[res_index_p50_sd]-_b[res_index_p90_sd]) 
display "Ho: coef >= 0  p-value = " 1-ttail(r(df_r),`sign_d'*sqrt(r(F)))

reg wagegap3_I1a_7717 res_index_p10_sd res_index_p50_sd res_index_p90_sd [pw=wagegap3_I1a_7717_se_wgt]
outreg2 using "${output_JP}table7", bdec(3) se br excel append

test res_index_p10_sd = res_index_p50_sd
local sign_d = sign(_b[res_index_p50_sd]-_b[res_index_p10_sd]) 
display "Ho: coef >= 0  p-value = " 1-ttail(r(df_r),`sign_d'*sqrt(r(F)))
test res_index_p90_sd = res_index_p50_sd
local sign_d = sign(_b[res_index_p50_sd]-_b[res_index_p90_sd]) 
display "Ho: coef >= 0  p-value = " 1-ttail(r(df_r),`sign_d'*sqrt(r(F)))

reg nevermarried_state3 res_index_p10_sd res_index_p50_sd res_index_p90_sd [pw=nevermarried_state3_se_wgt]
outreg2 using "${output_JP}table7", bdec(3) se br excel append

test res_index_p10_sd = res_index_p50_sd
local sign_d = sign(_b[res_index_p50_sd]-_b[res_index_p10_sd]) 
display "Ho: coef >= 0  p-value = " 1-ttail(r(df_r),`sign_d'*sqrt(r(F)))
test res_index_p90_sd = res_index_p50_sd
local sign_d = sign(_b[res_index_p50_sd]-_b[res_index_p90_sd]) 
display "Ho: coef >= 0  p-value = " 1-ttail(r(df_r),`sign_d'*sqrt(r(F)))

reg afc_state3 res_index_p10_sd res_index_p50_sd res_index_p90_sd [pw=afc_state3_se_wgt]
outreg2 using "${output_JP}table7", bdec(3) se br excel append

test res_index_p10_sd = res_index_p50_sd
local sign_d = sign(_b[res_index_p50_sd]-_b[res_index_p10_sd]) 
display "Ho: coef >= 0  p-value = " 1-ttail(r(df_r),`sign_d'*sqrt(r(F)))
test res_index_p90_sd = res_index_p50_sd
local sign_d = sign(_b[res_index_p50_sd]-_b[res_index_p90_sd]) 
display "Ho: coef >= 0  p-value = " 1-ttail(r(df_r),`sign_d'*sqrt(r(F)))

/*****************************************************************************************************************************/
/* Table 8: Relationship Between Alternative Percentiles of Male and Female Sexist Beliefs and Women's Labor Market Outcomes */
/*****************************************************************************************************************************/

use CG_tests_0721_temp, clear

macro define quantiles_men "res_index_men_p10_sd res_index_men_p50_sd res_index_men_p90_sd"
macro define quantiles_female "res_index_female_p10_sd res_index_female_p50_sd res_index_female_p90_sd"

set more off
reg lfgap3_7717 $quantiles_men [pw=lfgap3_7717_se_wgt]
outreg2 using "${output}table8", bdec(3) se br excel replace
reg lfgap3_7717 $quantiles_female [pw=lfgap3_7717_se_wgt]
outreg2 using "${output}table8", bdec(3) se br excel append
reg lfgap3_7717 $quantiles_men $quantiles_female [pw=lfgap3_7717_se_wgt]
outreg2 using "${output}table8", bdec(3) se br excel append

reg wagegap3_I1a_7717 $quantiles_men [pw=wagegap3_I1a_7717_se_wgt]
outreg2 using "${output}table8", bdec(3) se br excel append
reg wagegap3_I1a_7717 $quantiles_female [pw=wagegap3_I1a_7717_se_wgt]
outreg2 using "${output}table8", bdec(3) se br excel append
reg wagegap3_I1a_7717 $quantiles_men $quantiles_female [pw=wagegap3_I1a_7717_se_wgt]
outreg2 using "${output}table8", bdec(3) se br excel append

*hypothesis tests*

reg lfgap3_7717 $quantiles_men [pw=lfgap3_7717_se_wgt]

test res_index_men_p10_sd = res_index_men_p50_sd

local sign_d = sign(_b[res_index_men_p50_sd]-_b[res_index_men_p10_sd])  
display "Ho: coef <= 0  p-value = " ttail(r(df_r),`sign_d'*sqrt(r(F)))
display "Ho: coef >= 0  p-value = " 1-ttail(r(df_r),`sign_d'*sqrt(r(F)))

test res_index_men_p90_sd = res_index_men_p50_sd

local sign_d = sign(_b[res_index_men_p50_sd]-_b[res_index_men_p90_sd])  

display "Ho: coef <= 0  p-value = " ttail(r(df_r),`sign_d'*sqrt(r(F)))
display "Ho: coef >= 0  p-value = " 1-ttail(r(df_r),`sign_d'*sqrt(r(F)))

reg wagegap3_I1a_7717 $quantiles_men [pw=wagegap3_I1a_7717_se_wgt]

test res_index_men_p10_sd = res_index_men_p50_sd

local sign_d = sign(_b[res_index_men_p50_sd]-_b[res_index_men_p10_sd])  
display "Ho: coef <= 0  p-value = " ttail(r(df_r),`sign_d'*sqrt(r(F)))
display "Ho: coef >= 0  p-value = " 1-ttail(r(df_r),`sign_d'*sqrt(r(F)))

test res_index_men_p90_sd = res_index_men_p50_sd

local sign_d = sign(_b[res_index_men_p50_sd]-_b[res_index_men_p90_sd])  

display "Ho: coef <= 0  p-value = " ttail(r(df_r),`sign_d'*sqrt(r(F)))
display "Ho: coef >= 0  p-value = " 1-ttail(r(df_r),`sign_d'*sqrt(r(F)))

**

reg lfgap3_7717 $quantiles_men $quantiles_female [pw=lfgap3_7717_se_wgt]

test res_index_men_p10_sd = res_index_men_p50_sd

local sign_d = sign(_b[res_index_men_p50_sd]-_b[res_index_men_p10_sd])  
display "Ho: coef <= 0  p-value = " ttail(r(df_r),`sign_d'*sqrt(r(F)))
display "Ho: coef >= 0  p-value = " 1-ttail(r(df_r),`sign_d'*sqrt(r(F)))

test res_index_men_p90_sd = res_index_men_p50_sd

local sign_d = sign(_b[res_index_men_p50_sd]-_b[res_index_men_p90_sd])  

display "Ho: coef <= 0  p-value = " ttail(r(df_r),`sign_d'*sqrt(r(F)))
display "Ho: coef >= 0  p-value = " 1-ttail(r(df_r),`sign_d'*sqrt(r(F)))

reg wagegap3_I1a_7717 $quantiles_men $quantiles_female [pw=wagegap3_I1a_7717_se_wgt]

test res_index_men_p10_sd = res_index_men_p50_sd

local sign_d = sign(_b[res_index_men_p50_sd]-_b[res_index_men_p10_sd])  
display "Ho: coef <= 0  p-value = " ttail(r(df_r),`sign_d'*sqrt(r(F)))
display "Ho: coef >= 0  p-value = " 1-ttail(r(df_r),`sign_d'*sqrt(r(F)))

test res_index_men_p90_sd = res_index_men_p50_sd

local sign_d = sign(_b[res_index_men_p50_sd]-_b[res_index_men_p90_sd])  

display "Ho: coef <= 0  p-value = " ttail(r(df_r),`sign_d'*sqrt(r(F)))
display "Ho: coef >= 0  p-value = " 1-ttail(r(df_r),`sign_d'*sqrt(r(F)))

/*********************************************************************************************************************************/
/* Table 9: Relationship Between Alternative Percentiles of Male and Female Sexist Beliefs and Women's Non-Labor Market Outcomes */
/*********************************************************************************************************************************/

use CG_tests_0721_temp, clear

macro define quantiles_men "res_index_men_p10_sd res_index_men_p50_sd res_index_men_p90_sd"
macro define quantiles_female "res_index_female_p10_sd res_index_female_p50_sd res_index_female_p90_sd"

reg nevermarried_state3 $quantiles_men [pw=nevermarried_state3_se_wgt]
outreg2 using "${output}table9", bdec(3) se br excel replace
reg nevermarried_state3 $quantiles_female [pw=nevermarried_state3_se_wgt]
outreg2 using "${output}table9", bdec(3) se br excel append
reg nevermarried_state3 $quantiles_men $quantiles_female [pw=nevermarried_state3_se_wgt]
outreg2 using "${output}table9", bdec(3) se br excel append

reg afc_state3 $quantiles_men [pw=afc_state3_se_wgt]
outreg2 using "${output}table9", bdec(3) se br excel append
reg afc_state3 $quantiles_female [pw=afc_state3_se_wgt]
outreg2 using "${output}table9", bdec(3) se br excel append
reg afc_state3 $quantiles_men $quantiles_female [pw=afc_state3_se_wgt]
outreg2 using "${output}table9", bdec(3) se br excel append

/*****************************************************************/
/* Table A3: Convergence Over Time in Average State-Level Sexism */	
/* See prejudice_convergence_regs.do                             */
/*****************************************************************/

use state_prejudice_july2018_convergence, clear
drop res_index_men_mean res_index_female_mean res_index_mean
drop nres_index_men nres_index_female nres_index

drop if fipsstat==11
set logtype text
log using prejudice_index_spearman, replace
spearman prejudice_index_early prejudice_index_late if nprejudice_index_early>=15 & nprejudice_index_late>=15 & nprejudice_index_men_early>=15 & nprejudice_index_men_late>=15
spearman prejudice_index_men_early prejudice_index_men_late if nprejudice_index_men_early>=15 & nprejudice_index_men_late>=15 & nprejudice_index_female_early>=15 & nprejudice_index_female_late>=15
spearman prejudice_index_female_early prejudice_index_female_late if nprejudice_index_female_early>=15 & nprejudice_index_female_late>=15 & nprejudice_index_men_early>=15 & nprejudice_index_men_late>=15
log close

reshape long res_index_men_mean_ res_index_female_mean_ res_index_mean_ nres_index_men_ nres_index_female_ nres_index_ prejudice_index_men_mean_ prejudice_index_female_mean_ prejudice_index_mean_, i(state) j(year2)

drop if fipsstat==11
drop if res_index_mean_ == .

areg prejudice_index_mean_ if nres_index_>=15 & nres_index_female_>=15 & nres_index_men>=15, absorb(state)
areg prejudice_index_mean_ i.year if nres_index_>=15 & nres_index_female_>=15 & nres_index_men>=15, absorb(state)

areg prejudice_index_men_mean_ if nres_index_>=15 & nres_index_female_>=15 & nres_index_men>=15, absorb(state)
areg prejudice_index_men_mean_ i.year if nres_index_>=15 & nres_index_female_>=15 & nres_index_men>=15, absorb(state)

areg prejudice_index_female_mean_ if nres_index_>=15 & nres_index_female_>=15 & nres_index_men>=15, absorb(state)
areg prejudice_index_female_mean_ i.year if nres_index_>=15 & nres_index_female_>=15 & nres_index_men>=15, absorb(state)

/*******************************************************************************************/
/* Table A4: Convergence in Mean State Level Labor and Non-Labor Market Outcomes Over Time */ /*******************************************************************************************/

use CG_tests_0721_temp, clear

foreach i in "lfgap1" "lfgap3" "wagegap1" "wagegap3"{
rename `i'_7783 `i'_1980
rename `i'_8488 `i'_1986
rename `i'_8993 `i'_1991
rename `i'_9498 `i'_1996
rename `i'_9903 `i'_2001
rename `i'_0408 `i'_2006
rename `i'_0913 `i'_2011
rename `i'_1417 `i'_2016
}

foreach i in "lfgap1" "lfgap3" "wagegap1" "wagegap3"{
rename `i'_7783_se `i'_se_1980
rename `i'_8488_se `i'_se_1986
rename `i'_8993_se `i'_se_1991
rename `i'_9498_se `i'_se_1996
rename `i'_9903_se `i'_se_2001
rename `i'_0408_se `i'_se_2006
rename `i'_0913_se `i'_se_2011
rename `i'_1417_se `i'_se_2016
}

*rank correlations*
spearman lfgap1_7783 lfgap1_1417 if res_index_mean_sd~=.
spearman lfgap3_7783 lfgap3_1417 if res_index_mean_sd~=.

spearman wagegap1_7783 wagegap1_1417 if res_index_mean_sd~=.
spearman wagegap3_7783 wagegap3_1417 if res_index_mean_sd~=.


keep lfgap1_???? lfgap3_???? wagegap1_???? wagegap3_???? lfgap*_se_???? wagegap*_se_???? state

reshape long lfgap1_ wagegap1_ lfgap3_ wagegap3_, i(state) j(year2)

lab drop state
do "${data}fipsstat_state_bridge".do

gen statefip = fipsstat
capture drop _merge
merge m:1 fipsstat using state_prejudice_tomerge_dec2015

sort state
keep if _merge==1 | _merge==3

drop if res_index_mean_sd==.
drop if year2 == 7717 | year2 == 7797 | year2 == 9817

**convergence regs**

areg lfgap1_, absorb(statefip)
areg lfgap1_ i.year, absorb(statefip)

areg lfgap3_, absorb(statefip)
areg lfgap3_ i.year, absorb(statefip)

areg wagegap1_, absorb(statefip)
areg wagegap1_ i.year, absorb(statefip)

areg wagegap3_, absorb(statefip)
areg wagegap3_ i.year, absorb(statefip)

**For non-labor market outcomes using the census**

use census_state_gaps_convergence_0616, clear

rename nevermarried_state1 nevermarried_state1_9999
rename nevermarried_state3 nevermarried_state3_9999
rename nevermarried_state1_se nevermarried_state1_se_9999
rename nevermarried_state3_se nevermarried_state3_se_9999

rename afc_state1 afc_state1_9999
rename afc_state3 afc_state3_9999
rename afc_state1_se afc_state1_se_9999
rename afc_state3_se afc_state3_se_9999

foreach i in "1980" "1990" "2000" "2012"{
rename nevermarried`i'_state1 nevermarried_state1_`i'
rename nevermarried`i'_state1_se nevermarried_state1_se_`i'
rename nevermarried`i'_state3 nevermarried_state3_`i'
rename nevermarried`i'_state3_se nevermarried_state3_se_`i'
rename afc`i'_state1 afc_state1_`i'
rename afc`i'_state1_se afc_state1_se_`i'
rename afc`i'_state3 afc_state3_`i'
rename afc`i'_state3_se afc_state3_se_`i'
}

gen fipsstat = statefip
merge m:1 fipsstat using state_prejudice_tomerge_dec2015

reshape long nevermarried_state1_ nevermarried_state3_ afc_state1_ afc_state3_ nevermarried_state1_se_ nevermarried_state3_se_ afc_state1_se_ afc_state3_se_, i(state) j(year)

drop _merge
merge m:1 fipsstat using state_prejudice_tomerge_dec2015

sort state
keep if _merge==1 | _merge==3

drop if res_index_mean_sd==.

areg nevermarried_state1_ if year~=9999, absorb(statefip)
areg nevermarried_state1_ i.year if year~=9999, absorb(statefip)

areg nevermarried_state3_ if year~=9999, absorb(statefip)
areg nevermarried_state3_ i.year if year~=9999, absorb(statefip)

areg afc_state1_ if year~=9999, absorb(statefip)
areg afc_state1_ i.year if year~=9999, absorb(statefip)

areg afc_state3_ if year~=9999, absorb(statefip)
areg afc_state3_ i.year if year~=9999, absorb(statefip)

/*************************/
/* Table A5: First Stage */
/*************************/

use migrant_data_temp_labor, clear

set more off
xi: reg res_index_mean_sd geoIV res_index_mean_sd_bplxf res_index_mean_sd_bpl i.region_bpl*i.female i.female*i.year [pw=N_lf] if lf~=., cluster(statefip)
outreg2 using "${output_JP}tableA5", bdec(3) se br excel replace
test geoIV=0

xi: reg res_index_mean_sd mobIV40_sm res_index_mean_sd_bplxf res_index_mean_sd_bpl i.region_bpl*i.female i.female*i.year [pw=N_lf] if lf~=., cluster(statefip)
outreg2 using "${output_JP}tableA5", bdec(3) se br excel append
test mobIV40_sm=0

xi: reg res_index_mean_sd geoIV mobIV40_sm res_index_mean_sd_bplxf res_index_mean_sd_bpl i.region_bpl*i.female i.female*i.year [pw=N_lf] if lf~=., cluster(statefip)
outreg2 using "${output_JP}tableA5", bdec(3) se br excel append
test geoIV=mobIV40_sm=0
                                        
/*****************************************************************************************/
/* Table A6: Does Residential and Background Sexism Predict the Likelihood of Migration? */ 
/*****************************************************************************************/

global data2 "/Users/jessicapan/Dropbox (JPan)/current_projects/Sexism/data/"

use "${data2}census_merge_8012", clear

keep if bpl<100		//restricting analysis to US-born individuals
keep if age>=20 & age<=64

gen age2040=1 if age>=20 & age<=40
capture drop age2564
gen age2564=1 if age>=25 & age<=64

drop if statefip==11 | statefip_bpl==11

gen migrant = statefip~=statefip_bpl
replace migrant = . if statefip == . | statefip_bpl==.

gen migrant_f = migrant if female==1
gen migrant_m = migrant if female==0

**merging in prejudice measures**
merge m:1 fipsstat using "${collapsed_data}state_prejudice_tomerge_small"
keep if _merge==1 | _merge==3
drop _merge
merge m:1 statefip_bpl using "${collapsed_data}bplstate_prejudice_tomerge_sept2015"
keep if _merge==1 | _merge==3
drop _merge

**merging in instruments**
merge m:1 statefip_bpl using "${collapsed_data}sexism_IV_tomerge_apr2019"
drop if year==.
keep if _merge==1 | _merge==3
drop _merge

**merging in region info**
merge m:1 statefip using "${collapsed_data}state_region_bridge"
keep if _merge==1 | _merge==3
drop _merge
merge m:1 statefip_bpl using "${collapsed_data}state_region_bridge_bpl"
keep if _merge==1 | _merge==3
drop _merge

/* Probability of migration and average residential sexism */

set more off
xi: reg migrant res_index_mean_sd i.region_bpl*i.female i.age i.female*i.year educomp [pw=perwt] if age2564==1, cluster(statefip)
outreg2 using "${output_JP}tableA6_a", bdec(3) se br excel replace
xi: reg migrant res_index_mean_sd_bpl i.region_bpl*i.female i.age i.female*i.year educomp [pw=perwt] if age2564==1, cluster(statefip_bpl)
outreg2 using "${output_JP}tableA6_a", bdec(3) se br excel append
xi: reg migrant res_index_mean_sd res_index_mean_sd_bpl i.region_bpl*i.female i.age i.female*i.year educomp [pw=perwt] if age2564==1, cluster(statefip)
outreg2 using "${output_JP}tableA6_a", bdec(3) se br excel append

xi: reg migrant res_index_mean_sd i.region_bpl*i.female i.age i.female*i.year educomp [pw=perwt] if age2564==1 & female==1, cluster(statefip)
outreg2 using "${output_JP}tableA6_a", bdec(3) se br excel append
xi: reg migrant res_index_mean_sd_bpl i.region_bpl*i.female i.age i.female*i.year educomp [pw=perwt] if age2564==1 & female==1, cluster(statefip_bpl)
outreg2 using "${output_JP}tableA6_a", bdec(3) se br excel append
xi: reg migrant res_index_mean_sd res_index_mean_sd_bpl i.region_bpl*i.female i.age i.female*i.year educomp [pw=perwt] if age2564==1 & female==1, cluster(statefip)
outreg2 using "${output_JP}tableA6_a", bdec(3) se br excel append

xi: reg migrant res_index_mean_sd i.region_bpl*i.female i.age i.female*i.year educomp [pw=perwt] if age2564==1 & female==0, cluster(statefip)
outreg2 using "${output_JP}tableA6_a", bdec(3) se br excel append
xi: reg migrant res_index_mean_sd_bpl i.region_bpl*i.female i.age i.female*i.year educomp [pw=perwt] if age2564==1 & female==0, cluster(statefip_bpl)
outreg2 using "${output_JP}tableA6_a", bdec(3) se br excel append
xi: reg migrant res_index_mean_sd res_index_mean_sd_bpl i.region_bpl*i.female i.age i.female*i.year educomp [pw=perwt] if age2564==1 & female==0, cluster(statefip)
outreg2 using "${output_JP}tableA6_a", bdec(3) se br excel append

** using predicted residential sexism **

set more off
xi: reg migrant geoIV res_index_mean_sd_bpl i.region_bpl*i.female i.age i.female*i.year educomp [pw=perwt] if age2564==1, cluster(statefip)
outreg2 using "${output_JP}tableA6_b", bdec(3) se br excel replace
xi: reg migrant geoIV res_index_mean_sd_bpl i.region_bpl*i.female i.age i.female*i.year educomp [pw=perwt] if age2564==1 & female==1, cluster(statefip)
outreg2 using "${output_JP}tableA6_b", bdec(3) se br excel append
xi: reg migrant geoIV res_index_mean_sd_bpl i.region_bpl*i.female i.age i.female*i.year educomp [pw=perwt] if age2564==1 & female==0, cluster(statefip)
outreg2 using "${output_JP}tableA6_b", bdec(3) se br excel append

xi: reg migrant mobIV40_sm res_index_mean_sd_bpl i.region_bpl*i.female i.age i.female*i.year educomp [pw=perwt] if age2564==1, cluster(statefip)
outreg2 using "${output_JP}tableA6_b", bdec(3) se br excel append
xi: reg migrant mobIV40_sm res_index_mean_sd_bpl i.region_bpl*i.female i.age i.female*i.year educomp [pw=perwt] if age2564==1 & female==1, cluster(statefip)
outreg2 using "${output_JP}tableA6_b", bdec(3) se br excel append
xi: reg migrant mobIV40_sm res_index_mean_sd_bpl i.region_bpl*i.female i.age i.female*i.year educomp [pw=perwt] if age2564==1 & female==0, cluster(statefip)
outreg2 using "${output_JP}tableA6_b", bdec(3) se br excel append

/****************************************************************************/
/* Table A7: Robustness to Controls for State-Level Diffs in School Quality */ 
/****************************************************************************/

use CG_tests_0721_temp, clear

macro define quantiles "res_index_p10_sd res_index_p50_sd res_index_p90_sd"
macro define quantiles_men "res_index_men_p10_sd res_index_men_p50_sd res_index_men_p90_sd"
macro define quantiles_female "res_index_female_p10_sd res_index_female_p50_sd res_index_female_p90_sd"

macro define naep_boys "readz0 mathz0" 
macro define naep_girls "readz1 mathz1"

gen sample = 1 if mathz0~=.

set more off
reg lfgap3_7717 $quantiles_men [pw=lfgap3_7717_se_wgt] if sample==1 
outreg2 using "${output_JP}tableA7", bdec(3) se br excel replace
reg lfgap3_7717 $quantiles_men res_index_female_mean_sd [pw=lfgap3_7717_se_wgt] if sample==1
outreg2 using "${output_JP}tableA7", bdec(3) se br excel append
reg lfgap3_7717 $quantiles_men res_index_female_mean_sd $naep_boys [pw=lfgap3_7717_se_wgt] if sample==1
outreg2 using "${output_JP}tableA7", bdec(3) se br excel append

reg wagegap3_I1a_7717 $quantiles_men [pw=wagegap3_I1a_7717_se_wgt] if sample==1
outreg2 using "${output_JP}tableA7", bdec(3) se br excel append
reg wagegap3_I1a_7717 $quantiles_men res_index_female_mean_sd [pw=wagegap3_I1a_7717_se_wgt] if sample==1
outreg2 using "${output_JP}tableA7", bdec(3) se br excel append
reg wagegap3_I1a_7717 $quantiles_men res_index_female_mean_sd $naep_boys [pw=wagegap3_I1a_7717_se_wgt] if sample==1
outreg2 using "${output_JP}tableA7", bdec(3) se br excel append

/**********************************************************************/
/* Table A8: Sexism and Women's Outcomes, Controlling for Religiosity */ 
/**********************************************************************/
  
use CG_tests_0721_temp, clear

set more off
reg lfgap3_7717 res_index_men_mean_sd res_index_female_mean_sd res_attend_sd [pw=lfgap3_7717_se_wgt]
outreg2 using "${output_JP}tableA8", bdec(3) se br excel replace
reg wagegap3_I1a_7717 res_index_men_mean_sd res_index_female_mean_sd res_attend_sd [pw=wagegap3_I1a_7717_se_wgt]
outreg2 using "${output_JP}tableA8", bdec(3) se br excel append
reg nevermarried_state3 res_index_men_mean_sd res_index_female_mean_sd res_attend_sd [pw=nevermarried_state3_se_wgt]
outreg2 using "${output_JP}tableA8", bdec(3) se br excel append
reg afc_state3 res_index_men_mean_sd res_index_female_mean_sd res_attend_sd [pw=afc_state3_se_wgt]
outreg2 using "${output_JP}tableA8", bdec(3) se br excel append

reg lfgap3_7717 $quantiles_men $quantiles_female res_attend_sd [pw=lfgap3_7717_se_wgt]
outreg2 using "${output_JP}tableA8", bdec(3) se br excel append
reg wagegap3_I1a_7717 $quantiles_men $quantiles_female res_attend_sd [pw=wagegap3_I1a_7717_se_wgt]
outreg2 using "${output_JP}tableA8", bdec(3) se br excel append
reg nevermarried_state3 $quantiles_men $quantiles_female res_attend_sd [pw=nevermarried_state3_se_wgt]
outreg2 using "${output_JP}tableA8", bdec(3) se br excel append
reg afc_state3 $quantiles_men $quantiles_female res_attend_sd [pw=afc_state3_se_wgt]
outreg2 using "${output_JP}tableA8", bdec(3) se br excel append

/***************************************************************************/
/* Table A9: Sexism and Women's Outcomes, Controlling for Racial Attitudes */ 
/***************************************************************************/

use CG_tests_0721_temp, clear

set more off
reg lfgap3_7717 res_index_men_mean_sd res_index_female_mean_sd res_race_index_sd [pw=lfgap3_7717_se_wgt]
outreg2 using "${output_JP}tableA9", bdec(3) se br excel replace
reg wagegap3_I1a_7717 res_index_men_mean_sd res_index_female_mean_sd res_race_index_sd [pw=wagegap3_I1a_7717_se_wgt]
outreg2 using "${output_JP}tableA9", bdec(3) se br excel append
reg nevermarried_state3 res_index_men_mean_sd res_index_female_mean_sd res_race_index_sd [pw=nevermarried_state3_se_wgt]
outreg2 using "${output_JP}tableA9", bdec(3) se br excel append
reg afc_state3 res_index_men_mean_sd res_index_female_mean_sd res_race_index_sd [pw=afc_state3_se_wgt]
outreg2 using "${output_JP}tableA9", bdec(3) se br excel append

reg lfgap3_7717 $quantiles_men $quantiles_female res_race_index_sd [pw=lfgap3_7717_se_wgt]
outreg2 using "${output_JP}tableA9", bdec(3) se br excel append
reg wagegap3_I1a_7717 $quantiles_men $quantiles_female res_race_index_sd [pw=wagegap3_I1a_7717_se_wgt]
outreg2 using "${output_JP}tableA9", bdec(3) se br excel append
reg nevermarried_state3 $quantiles_men $quantiles_female res_race_index_sd [pw=nevermarried_state3_se_wgt]
outreg2 using "${output_JP}tableA9", bdec(3) se br excel append
reg afc_state3 $quantiles_men $quantiles_female res_race_index_sd [pw=afc_state3_se_wgt]
outreg2 using "${output_JP}tableA9", bdec(3) se br excel append
  
/*********************************************/
/* Table A10: Placebo Test Using Religiosity */ 
/*********************************************/

use CG_tests_0721_temp, clear

reg lfgap3_7717 $quantiles_men res_attend_p10_sd res_attend_p50_sd res_attend_p90_sd [pw=lfgap3_7717_se_wgt]
outreg2 using "${output_JP}tableA10", bdec(3) se br excel replace
reg wagegap3_I1a_7717 $quantiles_men res_attend_p10_sd res_attend_p50_sd res_attend_p90_sd [pw=wagegap3_I1a_7717_se_wgt]
outreg2 using "${output_JP}tableA10", bdec(3) se br excel append

reg lfgap3_7717 $quantiles_men res_attend_men_p10_sd res_attend_men_p50_sd res_attend_men_p90_sd [pw=lfgap3_7717_se_wgt]
outreg2 using "${output_JP}tableA10", bdec(3) se br excel replace
reg wagegap3_I1a_7717 $quantiles_men res_attend_men_p10_sd res_attend_men_p50_sd res_attend_men_p90_sd [pw=wagegap3_I1a_7717_se_wgt]
outreg2 using "${output_JP}tableA10", bdec(3) se br excel append

/**************************************************/
/* Table A11: Placebo Test Using Racial Attitudes */ 
/**************************************************/

use CG_tests_0721_temp, clear

reg lfgap3_7717 $quantiles_men res_race_index_p*_sd [pw=lfgap3_7717_se_wgt]
outreg2 using "${output_JP}tableA11", bdec(3) se br excel replace
reg wagegap3_I1a_7717 $quantiles_men res_race_index_p*_sd [pw=wagegap3_I1a_7717_se_wgt]
outreg2 using "${output_JP}tableA11", bdec(3) se br excel append

reg lfgap3_7717 $quantiles_men res_race_index_men_p*_sd [pw=lfgap3_7717_se_wgt]
outreg2 using "${output_JP}tableA11", bdec(3) se br excel append
reg wagegap3_I1a_7717 $quantiles_men res_race_index_men_p*_sd [pw=wagegap3_I1a_7717_se_wgt]
outreg2 using "${output_JP}tableA11", bdec(3) se br excel append

/****************************************************************/
/* Figure 1: Selected GSS Sexism Questions and Women's Outcomes */
/****************************************************************/

use CG_tests_0721_temp, clear

foreach var of varlist FEHOME-FEFAM_female{
replace `var' = . if res_index_mean_sd==.
}

set more off
# delimit ;
graph twoway scatter lfgap3_7717 FEWORK if res_index_mean_sd~=., mlabel(fipsstat) mlabsize(vsmall) msize(small) mlabpos(middle) scheme(s2mono) ||
lfit lfgap3_7717 FEWORK [aw=lfgap3_7717_se_wgt] if res_index_mean_sd~=., legend(off) ylabel(-0.25(0.05)0, labsize(medium)) xlabel(, labsize(medium))
ytitle("Residual LFP Gap (Female-Male)", size(medium)) xtitle("FEWORK: Married Women Earning Money if Husband Can Support Her" "% Disapprove", size(medium));
graph export "${output_JP}f2_lfgap_fework_7717.pdf", replace;

# delimit ;
graph twoway scatter rafc_state3 FEWORK if res_index_mean_sd~=., mlabel(fipsstat) mlabsize(vsmall) msize(small) mlabpos(middle) scheme(s2mono) ||
lfit rafc_state3 FEWORK [aw=afc_state3_se_wgt] if res_index_mean_sd~=., legend(off) ylabel(22(0.5)25, labsize(medium)) xlabel(, labsize(medium))
ytitle("Residual Age at First Child (Age 20-40)", size(medium)) xtitle("FEWORK: Married Women Earning Money if Husband Can Support Her" "% Disapprove", size(medium));
graph export "${output_JP}f2_afc_fework.pdf", replace;

# delimit ;
graph twoway scatter lfgap3_7717 FECHLD if res_index_mean_sd~=., mlabel(fipsstat) mlabsize(vsmall) msize(small) mlabpos(middle) scheme(s2mono) ||
lfit lfgap3_7717 FECHLD [aw=lfgap3_7717_se_wgt] if res_index_mean_sd~=., legend(off) ylabel(-0.25(0.05)0, labsize(medium)) xlabel(, labsize(medium))
ytitle("Residual LFP Gap (Female-Male)", size(medium)) xtitle("FECHILD: Working Mother Can Have Just as Warm a Relationship w/ Child" "1: Strongly Agree, 4: Strongly Disagree", size(medium));
graph export "${output_JP}f2_lfgap_fechld_7717.pdf", replace;

# delimit ;
graph twoway scatter rafc_state3 FECHLD if res_index_mean_sd~=., mlabel(fipsstat) mlabsize(vsmall) msize(small) mlabpos(middle) scheme(s2mono) ||
lfit rafc_state3 FECHLD [aw=afc_state3_se_wgt] if res_index_mean_sd~=., legend(off) ylabel(22(0.5)25, labsize(medium)) xlabel(, labsize(medium))
ytitle("Residual Age at First Child (Age 20-40)", size(medium)) xtitle("FECHILD: Working Mother Can Have Just as Warm a Relationship w/ Child" "1: Strongly Agree, 4: Strongly Disagree", size(medium));
graph export "${output_JP}f2_afc_fechld.pdf", replace;

/*********************************************/
/* Figure 2: Mean Overall Sexism in the U.S. */
/*********************************************/

label drop state
do "${data}fipsstat_state_bridge".do

capture drop _merge
statastates, fips(statefip)

rename state state1
rename state_abbrev state

maptile res_index_mean_sd, geo(state) nq(7) fcolor(gs12 gs10 gs8 gs6 gs4 gs2 gs1) ndfcolor(none) twopt(legend(lab(2 "Lowest: -1.66 - -0.92") lab(8 "Highest: 1.34 - 2.78") size(small))) 

graph use state_bw_cross.gph
graph export state_map_bw.tif, replace

/***************************************************************************************************************/
/* Figure 3: Predicted Residential Sexism based on: (a) Distance Between State of Birth and Other States, etc. */
/***************************************************************************************************************/

use state_prejudice_tomerge_mar2019, clear
keep fipsstat res_index_mean_sd 

rename fipsstat statefip_bpl
merge 1:1 statefip_bpl using sexism_IV_tomerge_apr2019

drop if res_index_mean_sd==.

# delimit ;
label define state 1	"	AL	"
2	"	AK	"
4	"	AZ	"
5	"	AR	"
6	"	CA	"
8	"	CO	"
9	"	CT	"
10	"	DE	"
11	"	DC	"
12	"	FL	"
13	"	GA	"
15	"	HI	"
16	"	ID	"
17	"	IL	"
18	"	IN	"
19	"	IA	"
20	"	KS	"
21	"	KY	"
22	"	LA	"
23	"	ME	"
24	"	MD	"
25	"	MA	"
26	"	MI	"
27	"	MN	"
28	"	MS	"
29	"	MO	"
30	"	MT	"
31	"	NE	"
32	"	NV	"
33	"	NH	"
34	"	NJ	"
35	"	NM	"
36	"	NY	"
37	"	NC	"
38	"	ND	"
39	"	OH	"
40	"	OK	"
41	"	OR	"
42	"	PA	"
44	"	RI	"
45	"	SC	"
46	"	SD	"
47	"	TN	"
48	"	TX	"
49	"	UT	"
50	"	VT	"
51	"	VA	"
53	"	WA	"
54	"	WV	"
55	"	WI	"
56	"	WY	";

lab val statefip_bpl state;

# delimit ;
scatter geoIV res_index_mean_sd, scheme(s2mono) ylabel(-3(1)3, labsize(small)) xlabel(, labsize(small))
ytitle("Predicted Overall Sexist Beliefs" "based on geographic distance", size(small)) mlabel(statefip_bpl)
xtitle("Overall Sexist Beliefs in State of Birth", size(small))
mlabsize(vsmall) msize(small) mlabpos(middle);
graph export "${output_JP}geoIV_fig.png", replace;

# delimit ;
scatter mobIV40_sm res_index_mean_sd, scheme(s2mono) ylabel(-3(1)3, labsize(small)) xlabel(, labsize(small))
ytitle("Predicted Overall Sexist Beliefs" "(based on 1930/1940 mobility patterns of single men)", size(small)) mlabel(statefip_bpl)
xtitle("Overall Sexist Beliefs in State of Birth", size(small))
mlabsize(vsmall) msize(small) mlabpos(middle);
graph export "${output_JP}mobIV_sm_fig.png", replace;

/*************************************************************/
/* Figure 4: R-Squared Statistics from Bivariate Regressions */
/*************************************************************/

use CG_tests_0721_temp, clear

*LFP*

gen r2_lfp3_all=.
gen r2_lfp3_men=.
gen r2_lfp3_female=.

gen run=.

forvalues i = 1/9{
replace run=`i'0 if _n==`i'
} 

forvalues i=10(10)90{
reg lfgap3_7717 res_index_p`i'_sd [pw=lfgap3_7717_se_wgt]
replace r2_lfp3_all= e(r2) if run==`i'
reg lfgap3_7717 res_index_men_p`i'_sd [pw=lfgap3_7717_se_wgt]
replace r2_lfp3_men= e(r2) if run==`i'
reg lfgap3_7717 res_index_female_p`i'_sd [pw=lfgap3_7717_se_wgt]
replace r2_lfp3_female= e(r2) if run==`i'
}

# delimit ;
scatter r2_lfp3_all run, msymbol(T) mcolor(gs3) || scatter r2_lfp3_men run, msymbol(Oh) mcolor(blue) || scatter r2_lfp3_female run, mcolor(red) msymbol(X) 
xlabel(10(10)90, labsize(small)) ylabel(0(0.1)0.4, labsize(small)) 
xtitle("Quantile of Sexist Beliefs", size(small)) ytitle(R-squared, size(small)) 
legend(label(1 "All") label(2 "Male") label(3 "Female") size(small) col(3)) scheme(s2mono)
title("Female-Male LFP", size(small)) xline(50, lcolor(gs8));
graph save "${output_JP}r2_lfp3_se_wgt_7717_new", replace;

/*
reg lfgap3_7717 res_index_mean_sd [pw=lfgap3_7717_se_wgt]
local r2 = e(r2)
graph bar (asis) r2_lfp3_all, over(run) yline(`r2')
*/

*Wages*

gen r2_wages3_all=.
gen r2_wages3_men=.
gen r2_wages3_female=.

forvalues i=10(10)90{
reg wagegap3_I1a_7717 res_index_p`i'_sd [pw=wagegap3_I1a_7717_se_wgt]
replace r2_wages3_all= e(r2) if run==`i'
reg wagegap3_I1a_7717 res_index_men_p`i'_sd [pw=wagegap3_I1a_7717_se_wgt]
replace r2_wages3_men= e(r2) if run==`i'
reg wagegap3_I1a_7717 res_index_female_p`i'_sd [pw=wagegap3_I1a_7717_se_wgt]
replace r2_wages3_female= e(r2) if run==`i'
}

# delimit ;
scatter r2_wages3_all run, msymbol(T) mcolor(gs3) || scatter r2_wages3_men run, msymbol(Oh) mcolor(blue) || scatter r2_wages3_female run, mcolor(red) msymbol(X) xlabel(10(10)90, labsize(small)) ylabel(0(0.1)0.35, labsize(small)) 
xtitle("Quantile of Sexist Beliefs", size(small)) ytitle(R-squared, size(small)) 
legend(label(1 "All") label(2 "Male") label(3 "Female") size(small) col(3) ) scheme(s2mono)
title("Selection-Corrected Female-Male Wage Gap", size(small)) xline(50, lcolor(gs8));
graph save "${output_JP}r2_wages3_se_wgt_7717_new", replace;

*Share Nevermarried*

gen r2_nm3_all=.
gen r2_nm3_men=.
gen r2_nm3_female=.

capture drop run
gen run=.
forvalues i = 1/9{
replace run=`i'0 if _n==`i'
} 

forvalues i=10(10)90{
reg nevermarried_state3 res_index_p`i'_sd [pw=nevermarried_state3_se_wgt]
replace r2_nm3_all= e(r2) if run==`i'
reg nevermarried_state3 res_index_men_p`i'_sd [pw=nevermarried_state3_se_wgt]
replace r2_nm3_men= e(r2) if run==`i'
reg nevermarried_state3 res_index_female_p`i'_sd [pw=nevermarried_state3_se_wgt]
replace r2_nm3_female= e(r2) if run==`i'
}

# delimit ;
scatter r2_nm3_all run, symbol(T) mcolor(gs3) || scatter r2_nm3_men run, msymbol(Oh) mcolor(blue) || scatter r2_nm3_female run, msymbol(X) mcolor(red) xlabel(10(10)90, labsize(small)) ylabel(0.1(0.1)0.45, labsize(small)) 
xtitle("Quantile of Sexist Beliefs", size(small)) ytitle(R-squared, size(small)) 
legend(label(1 "All") label(2 "Male") label(3 "Female") size(small) col(3)) scheme(s2mono)
title("Female Never Married Rate", size(small)) xline(50, lcolor(gs8));
graph save "${output_JP}r2_nm3_se_wgt_new", replace;

*Age First Child*

gen r2_afc3_all=. 
gen r2_afc3_men=.
gen r2_afc3_female=.

capture drop run
gen run=.
forvalues i = 1/9{
replace run=`i'0 if _n==`i'
} 

forvalues i=10(10)90{
reg afc_state3 res_index_p`i' [pw=afc_state3_se_wgt]
replace r2_afc3_all= e(r2) if run==`i'
reg afc_state3 res_index_men_p`i' [pw=afc_state3_se_wgt]
replace r2_afc3_men= e(r2) if run==`i'
reg afc_state3 res_index_female_p`i' [pw=afc_state3_se_wgt]
replace r2_afc3_female= e(r2) if run==`i'
}

# delimit ;
scatter r2_afc3_all run, msymbol(T) mcolor(g3) || scatter r2_afc3_men run, msymbol(Oh) mcolor(blue) || scatter r2_afc3_female run, msymbol(X) mcolor(red) xlabel(10(10)90, 
labsize(small)) ylabel(0.1(0.1)0.4, labsize(small)) 
xtitle("Quantile of Sexist Beliefs", size(small)) ytitle(R-squared, size(small)) 
legend(label(1 "All") label(2 "Male") label(3 "Female") size(small) col(3)) scheme(s2mono)
title("Female Age at First Child", size(small)) xline(50, lcolor(gs8));
graph save "${output_JP}r2_afc3_se_wgt_new", replace;

*Combining graphs*

grc1leg "${output_JP}r2_lfp3_se_wgt_7717_new.gph" "${output_JP}r2_wages3_se_wgt_7717_new.gph" "${output_JP}r2_nm3_se_wgt_new.gph" "${output_JP}r2_afc3_se_wgt_new.gph", iscale(0.8) scheme(s2mono)
graph export "${output_JP}r2_combine2_0919.pdf", replace

/******************************************************************************************/
/* Figure A1: Mean Residual Labor Market and Non-Labor Market Outcomes by Census Division */
/******************************************************************************************/

cd "/Users/jessicapan/Dropbox (JPan)/current_projects/Sexism/FINAL_2015/analysis_0915/collapsed_data/"

use cps_region_gap_7717, clear
drop division
tab regioncode

foreach i in "lfgap1" "lfgap3" "wagegap1" "wagegap3"{
rename `i'_7783 `i'_1980
rename `i'_8488 `i'_1986
rename `i'_8993 `i'_1991
rename `i'_9498 `i'_1996
rename `i'_9903 `i'_2001
rename `i'_0408 `i'_2006
rename `i'_0913 `i'_2011
rename `i'_1417 `i'_2016
}

foreach i in "lfgap1" "lfgap3" "wagegap1" "wagegap3"{
rename `i'_7783_se `i'_se_1980
rename `i'_8488_se `i'_se_1986
rename `i'_8993_se `i'_se_1991
rename `i'_9498_se `i'_se_1996
rename `i'_9903_se `i'_se_2001
rename `i'_0408_se `i'_se_2006
rename `i'_0913_se `i'_se_2011
rename `i'_1417_se `i'_se_2016
}

reshape long lfgap1_ wagegap1_ lfgap3_ wagegap3_ lfgap1_se_ wagegap1_se_ lfgap3_se_ wagegap3_se_, i(region) j(year2)

# delimit ;
graph twoway connect lfgap1_ year if region==1, msize(small)||
connect lfgap1_ year if region==2, msize(small) ||
connect lfgap1_ year if region==3, msize(small) msymbol(Th) ||
connect lfgap1_ year if region==4, msize(small) ||
connect lfgap1_ year if region==5,  ||
connect lfgap1_ year if region==6, msize(small) msymbol(plus) ||
connect lfgap1_ year if region==7, msize(small) ||
connect lfgap1_ year if region==8, msize(small) ||
connect lfgap1_ year if region==9, lpattern(_-) xlabel(1980(5)2017, labsize(small)) 
xtitle("Year", size(small)) ytitle("", size(small)) ylabel(-0.4(0.1)-0.1, labsize(small))
scheme(s2mono) title("A. Gender Gap in Labor Force Participation", size(small))
legend(label(1 "New England") label(2 "Middle Atlantic") label(3 "East N. Central") 
label(4 "West N. Central") label(5 "S. Atlantic") label(6 "East S. Central ") 
label(7 "West S. Central") label(8 "Mountain") label(9 "Pacific") 
size(vsmall) col(3)) ;
graph save "${output_JP}lfgap1_convergence_region_7717", replace;

# delimit ;
graph twoway connect wagegap1_ year if region==1, msize(small)||
connect wagegap1_ year if region==2, msize(small) ||
connect wagegap1_ year if region==3, msize(small) msymbol(Th) ||
connect wagegap1_ year if region==4, msize(small) ||
connect wagegap1_ year if region==5,  ||
connect wagegap1_ year if region==6, msize(small) msymbol(plus) ||
connect wagegap1_ year if region==7, msize(small) ||
connect wagegap1_ year if region==8, msize(small) ||
connect wagegap1_ year if region==9, lpattern(_-) xlabel(1980(5)2017, labsize(small)) 
xtitle("Year", size(small)) ytitle("", size(small)) ylabel(-0.5(0.1)-0.1, labsize(small))
scheme(s2mono) title("B. Gender Gap in Hourly Wage Among Employed", size(small))
legend(label(1 "New England") label(2 "Middle Atlantic") label(3 "East N. Central") 
label(4 "West N. Central") label(5 "S. Atlantic") label(6 "East S. Central ") 
label(7 "West S. Central") label(8 "Mountain") label(9 "Pacific") 
size(vsmall) col(3)) ;
graph save "${output_JP}wagegap1_convergence_region_7717", replace;

**CENSUS OUTCOMES**

use census_region_gaps_convergence_0616, clear

reshape long nevermarried1_ nevermarried3_ nevermarried1_se_ nevermarried3_se_ afc1_ afc3_ afc1_se afc3_se, i(region) j(year)

# delimit ;
graph twoway connect nevermarried1_ year if region==1, msize(small)||
connect nevermarried1_ year if region==2, msize(small) ||
connect nevermarried1_ year if region==3, msize(small) msymbol(Th) ||
connect nevermarried1_ year if region==4, msize(small) ||
connect nevermarried1_ year if region==5,  ||
connect nevermarried1_ year if region==6, msize(small) msymbol(plus) ||
connect nevermarried1_ year if region==7, msize(small) ||
connect nevermarried1_ year if region==8, msize(small) ||
connect nevermarried1_ year if region==9, lpattern(_-) xlabel(1980(5)2010, labsize(small)) 
xtitle("Year", size(small)) ytitle("", size(small)) ylabel(, labsize(small))
scheme(s2mono) title("C. Female Share Never Married (Age 20 to 30)", size(small))
legend(label(1 "New England") label(2 "Middle Atlantic") label(3 "East N. Central") 
label(4 "West N. Central") label(5 "S. Atlantic") label(6 "East S. Central ") 
label(7 "West S. Central") label(8 "Mountain") label(9 "Pacific") 
size(vsmall) col(3)) ;
graph save "${output_JP}nevermarried1_convergence_region", replace;

# delimit ;
graph twoway connect afc1_ year if region==1, msize(small)||
connect afc1_ year if region==2, msize(small) ||
connect afc1_ year if region==3, msize(small) msymbol(Th) ||
connect afc1_ year if region==4, msize(small) ||
connect afc1_ year if region==5,  ||
connect afc1_ year if region==6, msize(small) msymbol(plus) ||
connect afc1_ year if region==7, msize(small) ||
connect afc1_ year if region==8, msize(small) ||
connect afc1_ year if region==9, lpattern(_-) xlabel(1980(5)2010, labsize(small)) 
xtitle("Year", size(small)) ytitle("", size(small)) ylabel(, labsize(small))
scheme(s2mono) title("D. Female Age at First Birth (Age 20 to 30)", size(small))
legend(label(1 "New England") label(2 "Middle Atlantic") label(3 "East N. Central") 
label(4 "West N. Central") label(5 "S. Atlantic") label(6 "East S. Central ") 
label(7 "West S. Central") label(8 "Mountain") label(9 "Pacific") 
size(vsmall) col(3)) ;
graph save "${output_JP}afc1_convergence_region", replace;

* Combining Graph *

# delimit ;
grc1leg "${output_JP}lfgap1_convergence_region_7717.gph" "${output_JP}wagegap1_convergence_region_7717.gph" "${output_JP}nevermarried1_convergence_region.gph" "${output_JP}afc1_convergence_region.gph", iscale(0.7) scheme(s2mono) imargin(vsmall);
graph export "${output_JP}figure_A1.pdf", replace;

/***************************************************************************************/
/* Figure A2: Distance of States of Residence from States of Birth Among U.S. Migrants */
/***************************************************************************************/

use "${data2}census_merge_8012", clear

keep if bpl<100		//restricting analysis to US-born individuals
keep if age>=20 & age<=64

gen migrant = statefip~=statefip_bpl
replace migrant = . if statefip == . | statefip_bpl==.

keep if migrant==1

merge m:1 statefip_bpl statefip using "${data2}geodistance_long"
keep if _merge==1 | _merge==3

keep year perwt dist statefip_bpl statefip female

graph twoway hist dist [fw=perwt], percent scheme(s2mono) xtitle("Distance (Miles)") 
graph export ${output_JP}figure_A2.pdf, replace

/*************************************************************/
/* Figure A3: Sexism Among Men and Among Women in Each State */
/*************************************************************/

use CG_tests_0721_temp, clear

pwcorr res_index_female_mean_sd res_index_men_mean_sd if statefip~=11, sig
local rho: display %4.2fc r(rho)
display `rho'

local mean_f: display %4.0f r(mean) 

# delimit; 
graph twoway scatter res_index_female_mean_sd res_index_men_mean_sd if statefip~=11, mlabel(fipsstat) mlabsize(vsmall) msize(small) mlabpos(12) scheme(s2mono) 
ylabel(-2(1)3, labsize(small)) xlabel(-2(1)3, labsize(small)) legend(off)
ytitle("Standardized Female Sexism Index", size(small)) xtitle("Standardized Male Sexism Index", size(small))
text(-0.8 1.8 "Corr. Coef. = `rho'***", place(e) size(small));
graph export ${output_JP}figure_A3.pdf, replace;

/****************************************************************************************************/
/* Figure A4: Sensitivity of Regression Estimates to Omitting Observations from Diff. Indiv. States */
/****************************************************************************************************/

use CG_tests_0721_temp, clear

set more off
capture drop group
egen group=group(statefip) if res_index_mean~=.
sum group

gen lfgap_men_p10_coeff=.
gen lfgap_men_p50_coeff=.
gen lfgap_men_p90_coeff=.

forvalues i=1/44{
reg lfgap3_7717 $quantiles_men [pw=lfgap3_7717_se_wgt] if group~=`i'
replace lfgap_men_p10_coeff = _b[res_index_men_p10_sd] if _n==`i'
replace lfgap_men_p50_coeff = _b[res_index_men_p50_sd] if _n==`i'
replace lfgap_men_p90_coeff = _b[res_index_men_p90_sd] if _n==`i'
}

# delimit ;
graph twoway hist lfgap_men_p10_coeff, frac fcolor(gs10) bin(10) || hist lfgap_men_p50_coeff, frac fcolor(gs5) || hist lfgap_men_p90_coeff, frac fcolor(none)  scheme(s2mono) 
legend(label(1 "Male: 10th Pctile") label(2 "Male: 50th Pctile") label(3 "Male: 90th Pctile") col(3) size(small)) title("A. LFP Gap (Female-Male)", size(medium));
graph save "${output_JP}lfp_pctm_jk_7717", replace;

# delimit cr
gen wagegap_men_p10_coeff=.
gen wagegap_men_p50_coeff=.
gen wagegap_men_p90_coeff=.

forvalues i=1/44{
reg wagegap3_I1a_7717 $quantiles_men [pw=wagegap3_I1a_7717_se_wgt] if group~=`i'
replace wagegap_men_p10_coeff = _b[res_index_men_p10_sd] if _n==`i'
replace wagegap_men_p50_coeff = _b[res_index_men_p50_sd] if _n==`i'
replace wagegap_men_p90_coeff = _b[res_index_men_p90_sd] if _n==`i'
}

# delimit ;
graph twoway hist wagegap_men_p10_coeff, frac fcolor(gs10) bin(5) || hist wagegap_men_p50_coeff, frac fcolor(gs5)  bin(10) ||  hist wagegap_men_p90_coeff, frac fcolor(none) bin(5) scheme(s2mono)
legend(label(1 "Male: 10th Pctile") label(2 "Male: 50th Pctile") label(3 "Male: 90th Pctile") col(3) size(small)) title("B. Selection-Corrected Wage Gap (Female-Male)", size(medium));
graph save "${output_JP}wage_pctm_jk_7717", replace;

# delimit cr
gen nm_female_p10_coeff=.
gen nm_female_p50_coeff=.
gen nm_female_p90_coeff=.

forvalues i=1/44{
reg nevermarried_state3 $quantiles_female [pw=nevermarried_state3_se_wgt] if group~=`i'
replace nm_female_p10_coeff = _b[res_index_female_p10_sd] if _n==`i'
replace nm_female_p50_coeff = _b[res_index_female_p50_sd] if _n==`i'
replace nm_female_p90_coeff = _b[res_index_female_p90_sd] if _n==`i'
}

# delimit ;
graph twoway hist nm_female_p10_coeff, frac fcolor(gs10) bin(10) || hist nm_female_p50_coeff, frac fcolor(gs5)  scheme(s2mono) bin(10) ||  hist nm_female_p90_coeff, frac fcolor(none) bin(5)
legend(label(1 "Female: 10th Pctile") label(2 "Female: 50th Pctile") label(3 "Female: 90th Pctile") col(3) size(small)) title("C. Female Share Never Married (Age 20 to 40)", size(medium));
graph save "${output_JP}nm_pctf_jk", replace;

# delimit cr
gen afc_female_p10_coeff=.
gen afc_female_p50_coeff=.
gen afc_female_p90_coeff=.

forvalues i=1/44{
reg afc_state3 $quantiles_female [pw=afc_state3_se_wgt] if group~=`i'
replace afc_female_p10_coeff = _b[res_index_female_p10_sd] if _n==`i'
replace afc_female_p50_coeff = _b[res_index_female_p50_sd] if _n==`i'
replace afc_female_p90_coeff = _b[res_index_female_p90_sd] if _n==`i'
}

# delimit ;
graph twoway hist afc_female_p10_coeff, frac fcolor(gs10) || hist afc_female_p50_coeff, frac fcolor(gs5)  scheme(s2mono) ||  hist afc_female_p90_coeff, frac fcolor(none) 
legend(label(1 "Female: 10th Pctile") label(2 "Female: 50th Pctile") label(3 "Female: 90th Pctile") col(3) size(small))title("D. Age at First Birth (Age 20 to 40)", size(medium));
graph save "${output_JP}afc_pctf_jk", replace;

# delimit cr
graph combine "${output_JP}lfp_pctm_jk_7717.gph" "${output_JP}wage_pctm_jk_7717.gph" "${output_JP}nm_pctf_jk.gph" "${output_JP}afc_pctf_jk.gph", iscale(0.44) scheme(s2mono) imargin(vsmall)
graph export "${output_JP}figure_A4.pdf", replace
